﻿using ETA.DtoMappings;
using ETA.Entity;
using ETA.IService;
using Ninject;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ETA.UnitTest
{
    [TestFixture]
    public class RegistrationMainFormServiceTest
    {
        private static IRegistrationMainFormService _IRegistrationMainFormService { set; get; }
        private static IUserService _IUserService { set; get; }
        private static IFlowStepService _IFlowStepService { set; get; }
        [SetUp]
        public void Init()
        {
            DtoMapConfig.InitMap();
            IKernel kernel = new StandardKernel(new NinjectModuleBuild());
            _IRegistrationMainFormService = kernel.Get<IRegistrationMainFormService>();
            _IUserService = kernel.Get<IUserService>();
            _IFlowStepService = kernel.Get<IFlowStepService>();
        }

        [Test]
        public void TestAddRegistrationMainForm()
        {
            FlowStep currentStep = null;
            var queryFlowStepResponse = _IFlowStepService.QueryFlowStepList(
                new QueryFlowStepRequest
                {
                    FlowStep = new FlowStep
                    {
                        FlowIndex = 1
                    }
                });
            if (queryFlowStepResponse.Result.IsSuccess)
            {
                currentStep = queryFlowStepResponse.FlowSteps.FirstOrDefault();
            }

            var req = new QueryUserRequest
            {
                User = new User
                {
                    LoginName = "skyforce2008"
                }
            };

            var response = _IUserService.QueryUser(req);
            var form = new RegistrationMainForm
            {
                RegistrationMainFormId = Guid.NewGuid() + "",
                User = response.Users.FirstOrDefault(),
                CurrentStep = currentStep
            };
            var res = _IRegistrationMainFormService
                .CreateRegistrationMainForm(
                new CreateRegistrationMainFormRequest { RegistrationMainForm = form });
            Assert.True(res.Result.IsSuccess);
        }

        public void TestModifyRegistrationMainForm()
        {
            var response = _IRegistrationMainFormService.QueryRegistrationMainFormList(new QueryRegistrationMainFormRequest
            {
                UserId = "a2bf124c-4467-4b31-8d59-8cb079882f51"
            });

        }

        [Test]
        public void TestUpdateCurrentStep()
        {
            var result = _IRegistrationMainFormService.UpdateCurrentStep("27362b13-a120-448a-8ad5-3a8e39525068", "9d95dcb0-8f10-4aa7-9dc8-148d57d83c69");
            Assert.True(result);
        }
    }
}
